<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 代理Proxy
        let obj = {
            name: "李老师",
            age: 12
        };
        let handel = {
            // 设置
            set: function(target, key, value) {
                console.log("1,李老师的水发生变化", target, key, value);
                if (value < 0) {
                    return;
                }
                target[key] = value;
            },
            // 获取
            get: function(target, key) {
                console.log("2,有人想看李老师的水", target, key);
                return target[key]
            }
        }
        let proxy = new Proxy(obj, handel);
        proxy.waiter = -34;
        console.log("结果", proxy);
        console.log("获取内容", proxy.waiter);
    </script>
</body>

</html>